package com.attunlcok.unlock.controller;

import java.util.List;

import com.attunlcok.common.annotation.Anonymous;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.attunlcok.common.annotation.Log;
import com.attunlcok.common.enums.BusinessType;
import com.attunlcok.unlock.domain.AttUnlockRecord;
import com.attunlcok.unlock.service.IAttUnlockRecordService;
import com.attunlcok.common.core.controller.BaseController;
import com.attunlcok.common.core.domain.AjaxResult;
import com.attunlcok.common.utils.poi.ExcelUtil;
import com.attunlcok.common.core.page.TableDataInfo;

/**
 * IMEI解锁记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/unlock/AttUnlockRecord")
public class AttUnlockRecordController extends BaseController
{
    private String prefix = "unlock/AttUnlockRecord";

    @Autowired
    private IAttUnlockRecordService attUnlockRecordService;

    @RequiresPermissions("unlock:AttUnlockRecord:view")
    @GetMapping()
    public String AttUnlockRecord()
    {
        return prefix + "/AttUnlockRecord";
    }

    /**
     * 查询IMEI解锁记录列表
     */
    @RequiresPermissions("unlock:AttUnlockRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AttUnlockRecord attUnlockRecord)
    {
        startPage();
        List<AttUnlockRecord> list = attUnlockRecordService.selectAttUnlockRecordList(attUnlockRecord);
        return getDataTable(list);
    }

    /**
     * 导出IMEI解锁记录列表
     */
    @RequiresPermissions("unlock:AttUnlockRecord:export")
    @Log(title = "IMEI解锁记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AttUnlockRecord attUnlockRecord)
    {
        List<AttUnlockRecord> list = attUnlockRecordService.selectAttUnlockRecordList(attUnlockRecord);
        ExcelUtil<AttUnlockRecord> util = new ExcelUtil<AttUnlockRecord>(AttUnlockRecord.class);
        return util.exportExcel(list, "IMEI解锁记录数据");
    }

    /**
     * 新增IMEI解锁记录
     */
    @RequiresPermissions("unlock:AttUnlockRecord:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存IMEI解锁记录
     */
    @RequiresPermissions("unlock:AttUnlockRecord:add")
    @Log(title = "IMEI解锁记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AttUnlockRecord attUnlockRecord)
    {
        return toAjax(attUnlockRecordService.insertAttUnlockRecord(attUnlockRecord));
    }

    /**
     * 批量创建IMEI解锁记录
     */
    @Anonymous
    @Log(title = "IMEI解锁记录", businessType = BusinessType.INSERT)
    @GetMapping("/batchCreate")
    @ResponseBody
    public AjaxResult batchCreate(String imeis)
    {
        return toAjax(attUnlockRecordService.batchCreateUnlockRecords(imeis));
    }

    /**
     * 修改IMEI解锁记录
     */
    @RequiresPermissions("unlock:AttUnlockRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AttUnlockRecord attUnlockRecord = attUnlockRecordService.selectAttUnlockRecordById(id);
        mmap.put("attUnlockRecord", attUnlockRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存IMEI解锁记录
     */
    @RequiresPermissions("unlock:AttUnlockRecord:edit")
    @Log(title = "IMEI解锁记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AttUnlockRecord attUnlockRecord)
    {
        return toAjax(attUnlockRecordService.updateAttUnlockRecord(attUnlockRecord));
    }

    /**
     * 删除IMEI解锁记录
     */
    @RequiresPermissions("unlock:AttUnlockRecord:remove")
    @Log(title = "IMEI解锁记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(attUnlockRecordService.deleteAttUnlockRecordByIds(ids));
    }
}
